const {app,BrowserWindow,Menu, ipcMain} = require('electron')
const path=require('path')
const template=[
  {label:'open new BrowserWindow',click:()=>{
    createSubWindow()
  }},
  {label:'devtools',role:'toggleDevTools'}
]
let win =null
app.whenReady().then(() => {
 console.log('whenReady');
  createWindow = () => {
  win= new BrowserWindow({
    width: 800,
    height: 600,
    webPreferences:{
      nodeIntegration:true,
      contextIsolation:false
      // preload:path.join(__dirname,'home.js')
    }
  })
  const menu=Menu.buildFromTemplate(template)
  Menu.setApplicationMenu(menu)
  win.loadFile('index.html')
}
 createWindow()
})
let subwin=null
createSubWindow = () => {
  subwin = new BrowserWindow({
      width: 800,
      height: 600,
      webPreferences:{
        nodeIntegration:true,
        contextIsolation:false
        // preload:path.join(__dirname,'home.js')
      }
    })
  subwin.loadFile('add.html')
}
ipcMain.on('addtext',(e,value)=>{
  console.log(value);
  win.webContents.send('render',value)
})
ipcMain.on('removeTime',(event,value)=>{
  console.log(value,'removeTime');
  subwin.webContents.send('subRemoveTime',value)
  
})
